Determining Heading Using Magnetometer Data and Angular Rate Data

ABSTRACT

A device coupled with a magnetometer and an angular rate sensor can determine a heading of the device using magnetometer data. When the device receives a notification that the magnetometer data may be inaccurate, the device can determine the heading of the device using angular rate data. When the device determines that the magnetometer data are accurate, the device can resume determining the heading of the device using the magnetometer data.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application claims priority to pending U.S. Provisional Application Ser. No. 61/319,139, entitled “Calibrating Sensor Measurements on Mobile Devices”, filed on Mar. 30, 2010, and pending U.S. Provisional Application Ser. No. 61/356,550, entitled “Determining Heading Using Magnetometer Data and Angular Rate Data,” filed Jun. 18, 2010, the entire contents of each of which are hereby incorporated by reference.

TECHNICAL FIELD

This disclosure relates generally to determining a heading of a mobile device.

BACKGROUND

Angular rate sensors are used to measure the rotational velocity of an object without a fix point for referencing. A Micro-Electro-Mechanical System (MEMS) angular rate sensor (or MEMS gyro) can be incorporated into mobile devices due to its small size, weight and low cost. The principle of operation is based on the Coriolis effect. A MEMS resonator is driven at a certain frequency (e.g., about 10 kHz). Due to the angular rate the Coriolis force excites a second oscillation perpendicular to the first one. This oscillation is proportional to the angular rate and can be measured using capacitive methods. Application examples include but are not limited to: image stabilisation (e.g., in cameras or mobile phones); input devices for virtual reality applications; platform stabilisation; sensors for game consoles; and sensors for navigation systems.

The MEMS gyro is susceptible to bias, scale factor errors, and axis cross-sensitivities, as well as high frequency noise. Cross-axis sensitivity is strongly affected by mounting stresses, while the magnitudes of the bias and scale factor errors are related to external temperature. For example, changes in gyro bias are approximately linear to changes in external temperature. To mitigate the effects of gyro bias, the gyro bias can be estimated using known mathematical formulations and subtracted from the raw gyro data. Calibration using measurements at known angular rates can be used to determine the cross-axis sensitivity. Unfortunately, constraints on processing speed, power and memory can make these mathematical formulations impracticable for applications running on mobile devices with limited resources.

SUMMARY

Sensor measurements are used to detect when a device incorporating the sensor is stationary. While the device is stationary, sensor measurements at a current device temperature are used to estimate model parameters. The model parameters can be used in a state estimator to provide an estimated attitude that can be provided to other applications. In some implementations, the estimated attitude can be used to mitigate interference in other sensor measurements.

A device coupled with a magnetometer and an angular rate sensor can determine a heading of the device using magnetometer data. When the device receives an indication that the magnetometer data may be inaccurate, the device can determine the heading of the device using angular rate data. When the device determines that the magnetometer data are accurate, the device can resume determining the heading of the device using the magnetometer data.

The details of one or more implementations of calibrating sensor measurements on mobile devices are set forth in the accompanying drawings and the description below. Other features, aspects, and advantages of calibrating sensor measurements on mobile devices will become apparent from the description, the drawings, and the claims.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of an exemplary sensor measurement calibration system.

FIG. 2 is a flow diagram illustrating various exemplary processes performed by the state estimator of FIG. 1.

FIG. 3 is a flow diagram of an exemplary process for estimating model parameters and determining an estimated attitude based on the model parameters.

FIG. 4A illustrates an exemplary Cartesian coordinate system describing the Earth's geomagnetic field in accordance with some implementations.

FIG. 4B illustrates an exemplary 2-axis magnetometer in accordance with some implementations.

FIG. 4C is a block diagram of an exemplary system for determining heading using magnetometer data and angular rate data.

FIG. 4D is a flow diagram of an exemplary process of determining heading using magnetometer data and angular rate data.

FIG. 5 is a block diagram of an exemplary hardware architecture for implementing the system and processes referenced in FIGS. 1-4.

Like reference symbols in the various drawings indicate like elements.

DETAILED DESCRIPTION Exemplary Sensor Measurement Calibration System

FIG. 1 is a block diagram of an exemplary sensor measurement calibration system 100. In some implementations, system 100 can include an angular rate sensor 102 (e.g., a MEMS gyro), motion detector 104, model parameter estimator 106, state estimator 108, calibration database 110, accelerometer 112 and an optional interference mitigation module 114. System 100 can be incorporated in a variety of mobile devices, including but not limited to: a handheld computer, a personal digital assistant (PDA), a cellular telephone, an electronic tablet, a network appliance, a digital camera, a video camera, a smart phone, an enhanced general packet radio service (EGPRS) mobile phone, a media player, a navigation device, an email device, a game console, or a combination of any two or more of these devices. In some implementations, some or all of the components of system 100 can be included on one or more integrated circuit (IC) chips.

In some implementations, an attitude of a device can be updated using body angular rates. The body angular rates can be represented by an angular rates vector {right arrow over (ω)}. The components of the angular rates vector {right arrow over (ω)} represent angular rates in the x, y and z axes, respectively, in a local coordinate frame of the device. In some implementations, the angular rates vector {right arrow over (ω)} can be measured using three MEMS gyros, one on each of the x, y and z axes of the local coordinate frame.

Generally, the attitude of the device can be represented by a reference quaternion {right arrow over (q)}_(ref) a follows:

{right arrow over (q)} _(ref) [q _(x) q _(y) q _(z) q _(w)]^(T),  (1)

q _(w)=cos(f/2)

q _(x) =J _(x) sin(f/2)′

q _(y) =J _(y) sin(f/2)

q _(z) =J _(z) sin(f/2)

where

-   -   {right arrow over (J)}=unit vector along axis of rotation     -   f=total rotation angle.

A reference quaternion change rate formulation based on a small angle approximation is given by

$\begin{matrix} {\begin{bmatrix} {\overset{.}{q}}_{x} \\ {\overset{.}{q}}_{y} \\ {\overset{.}{q}}_{z} \\ {\overset{.}{q}}_{w} \end{bmatrix} = {{{\frac{1}{2}\begin{bmatrix} q_{w} & {- q_{z}} & {- q_{y}} \\ q_{z} & q_{w} & {- q_{x}} \\ q_{y} & q_{x} & q_{w} \\ {- q_{x}} & {- q_{y}} & {- q_{z}} \end{bmatrix}}\begin{bmatrix} \omega_{x} \\ \omega_{y} \\ \omega_{z} \end{bmatrix}}{{t}.}}} & (2) \end{matrix}$

Equation (2) can be integrated in discrete time to obtain the final attitude of the device represented by reference quaternion {right arrow over (q)}_(ref).

The angular rate vector {right arrow over (ω)} is output from angular sensor 102 and input to motion detector 104. Additionally, a current temperature T of the device is input to motion detector 104. The current temperature T can be provided by a temperature sensor in angular sensor 102 or located elsewhere in the device. In some implementations, the angular rate vector {right arrow over (ω)} can be scale-corrected before input into motion detector 104.

In some implementations, motion detector 104 identifies when the device is stationary. Let {right arrow over (ω)}₁ . . . {right arrow over (ω)}_(n) be the latest n samples of angular rate from a three axis angular sensor 102, expressed in degrees per second. Let T₁ . . . T_(n) be the latest angular sensor temperature samples corresponding to the angular rates {right arrow over (ω)}₁ . . . . {right arrow over (ω)}_(n).

At each new calibration time t, the following quantities are updated per axis:

$\begin{matrix} {{\overset{\_}{\omega} = {\frac{1}{n}{\sum\limits_{i = 1}^{n}\omega_{i}}}},} & (3) \\ {{{\overset{\_}{\omega}}^{2} = {\frac{1}{n}{\sum\limits_{i = 1}^{n}\omega_{i}^{2}}}},} & (4) \\ {\overset{\_}{T} = {\frac{1}{n}{\sum\limits_{i = 1}^{n}{T.}}}} & (5) \end{matrix}$

And from equations (3) and (4), the variance per axis is given by:

σ²= ω ²−({right arrow over (ω)})².  (6)

Since the angular rate should theoretically be zero if the device is stationary, if σ² is less than a threshold ω can be used as an estimate of the angular rate bias at the current temperature T. ω, T (collectively, referred to as a “calibration point”) and the calibration time t can be stored in calibration database 110. Old values of ω, T stored in calibration database 110 that have a temperature close to T can be removed. Calibration database 110 can be updated as the device ages. For example, an aging algorithm can be applied where the oldest calibration points are removed from calibration database 110 on a scheduled basis or in response to a trigger event. For example, calibration database 110 can be pruned of all but the N latest calibration points in each 1° C. temperature bin. Additionally, {right arrow over ({right arrow over (ω)} can be input to state estimator 108 as a measurement of the current angular sensor bias.

In some implementations, model parameter estimator 106 can track a linear approximation of the calibration points stored in calibration database 110. For example, as calibration points are added to calibration database 110, model parameter estimator 106 can track the following quantities per axis:

$\begin{matrix} {\sum\limits_{i = 1}^{n}T_{i}} & (7) \\ {{\sum\limits_{i = 1}^{n}T_{i}^{2}},} & (8) \\ {{\sum\limits_{i = 1}^{n}\omega_{i}},} & (9) \\ {\sum\limits_{i = 1}^{n}{\omega_{i}{T_{i}.}}} & (10) \end{matrix}$

The angular rate bias versus temperature slope, m, can be computed per axis from equations (7)-(10) as:

$\begin{matrix} {\left. {m = {\left\lbrack {{n{\sum\limits_{i = 1}^{n}T_{i}^{2}}} - \left( {\sum\limits_{i = 1}^{n}T_{i}} \right)^{2}} \right\rbrack\left\lbrack {{n{\sum\limits_{i = 1}^{n}\left( {\omega_{i}T_{i}} \right)}} - {\left( {\sum\limits_{i = 1}^{n}T_{i}} \right)\left( {\sum\limits_{i = 1}^{n}\omega_{i}} \right)}} \right\rbrack}} \right\rbrack.} & (11) \end{matrix}$

The angular rate bias versus temperature offset, b, can be computed per axis from equations (7)-(10) as:

$\begin{matrix} {\left. {b = {\left\lbrack {{n{\sum\limits_{i = 1}^{n}T_{i}^{2}}} - \left( {\sum\limits_{i = 1}^{n}T_{i}} \right)^{2}} \right\rbrack\left\lbrack {{\left( {\sum\limits_{i = 1}^{n}T_{i}^{2}} \right)\left( {\sum\limits_{i = 1}^{n}\omega_{i}} \right)} - {\left( {\sum\limits_{i = 1}^{n}T_{i}} \right)\left( {\sum\limits_{i = 1}^{n}{\omega_{i}T_{i}}} \right)}} \right\rbrack}} \right\rbrack.} & (12) \end{matrix}$

For three axis sensors, a temperature slope vector Fri and temperature bias offset vector {right arrow over (b)}=[b_(x) b_(y) b_(z)] are input to state estimator 108, where these vector quantities are used to compute an estimated attitude of the device using an attitude estimation filter, as described in reference to FIG. 2.

FIG. 2 is a flow diagram illustrating various exemplary processes performed by the state estimator 108 of FIG. 1. In some implementations, state estimator 108 can implement update paths 200-204 for updating state variables. In this example, angular rate sensor 102 can be a three-axis MEMS gyro.

A first path 200 can perform a temperature estimate update using a temperature estimation filter, the current temperature T and the estimated temperature slope vector {right arrow over (m)} received from model parameter estimator 106. The slope vector {right arrow over (m)} and temperature bias offset vector {right arrow over (b)} define a linear model that describes a base bias vector {right arrow over (b)}_(base) for a given temperature T given by:

{right arrow over (b)} _(base) ={right arrow over (m)}*T+{right arrow over (b)}.  (13)

A bias delta vector {right arrow over (β)} can then be defined by the difference between the true bias at a given time {right arrow over (b)}_(true) and the base bias vector {right arrow over (b)}_(base) as follows:

{right arrow over (β)}={right arrow over (b)} _(true) −{right arrow over (b)} _(base),  (14)

where the base bias vector {right arrow over (b)}_(base) accounts for the bias over a long period of time and the bias delta vector {right arrow over (β)} accounts for the bias for local (in time) variation.

A second update path 201 can perform an acceleration update using an acceleration vector {right arrow over (a)} received from accelerometer 112. The acceleration vector {right arrow over (a)} can be scale-corrected before it is input into state estimator 108. If the acceleration vector has too much dynamic acceleration, the update can be completed without further action by state estimator 108. If the acceleration vector does not have too much dynamic acceleration, a time update can be performed and a gravity vector {right arrow over (g)} can be computed in the local coordinate frame of the device. The gravity vector and other quantities can be used in an attitude estimation filter as described below.

A third update path 202 can perform a gyro update by first subtracting the base bias vector {right arrow over (b)}_(base) from the angular rate vector {right arrow over (ω)} to generate a temperature compensated angular rate vector {right arrow over (ω)}_(c)=({right arrow over (ω)}−m*T−b)=[ω_(cx) ω_(cy) ω_(cz)] and then subtracting the bias delta vector {right arrow over (β)} from the compensated angular rate vector {right arrow over (ω)}_(c) to generate an estimated angular rate vector {right arrow over ({circumflex over (ω)}=({right arrow over (ω)}_(c)−β)=[{circumflex over (ω)}_(x) {circumflex over (ω)}_(y) {circumflex over (ω)}_(z)] and storing the estimated angular rate vector in a buffer. The reference quaternion, {right arrow over (q)}_(ref), can be propagated using equation (15) below:

q _(delta)=[ sin(|{right arrow over ({circumflex over (ω)}|*dt/2)*{right arrow over ({circumflex over (ω)}/|{right arrow over ({circumflex over (ω)}|,cos(|{right arrow over ({circumflex over (ω)}*dt/2)],

{right arrow over (q)} _(ref) =q _(delta)

{right arrow over (q)} _(ref),  (15)

where

is quaternion multiplication.

Other approximations or formulations for updating quaternion or direction cosine matrix formulations can also be used. If the estimated angular rate vector {right arrow over ({circumflex over (ω)} diverges from the actual angular rate vector {right arrow over (ω)}, a time update can be performed. If the magnitude of the temperature compensated angular rate {right arrow over (ω)}_(c) is less than some predetermined threshold a low pass filter (LPF) can be updated as described below.

A fourth update path 203 can perform a gyro bias update by computing a estimated angular rate vector {right arrow over ({circumflex over (ω)} and updating the state of bias delta vector {right arrow over (β)} using the attitude estimation filter.

A fifth update path 204 can perform a gyro bias linear fit update by replacing the temperature bias model in the attitude estimation filter with the new model provided, updating the bias delta vector {right arrow over (β)} and the LPF appropriately.

Exemplary Kalman Filter Formulations

The temperature estimation filter and attitude estimation filter referenced above can be implemented using Kalman filter formulations to improve accuracy. In some implementations, two independent Kalman filters can be used: one to estimate temperature, and one to estimate attitude. The Kalman filters can be decoupled for computational efficiency reasons as well as logical reasons.

In some implementations, the temperature estimation filter can be a classic Kalman Filter with temperature T and temperature rate {dot over (T)} as states. The temperature estimation filter state and temperature estimation filter transition matrix can be represented by:

$\begin{matrix} {{X = \begin{pmatrix} T \\ \overset{.}{T} \end{pmatrix}},} & (16) \\ {\Phi = {\begin{pmatrix} 1 & {\Delta \; t} \\ 0 & 1 \end{pmatrix}.}} & (17) \end{matrix}$

The attitude estimation filter can be based on a multiplicative extended Kalman filter formulation. The filter can propagate the reference quaternion {right arrow over (q)}_(ref) with the compensated angular rate vector {right arrow over (ω)}_(c). The attitude estimation filter state can include a local attitude error vector {right arrow over (θ)} derived from the reference quaternion {right arrow over (q)}_(ref) and the bias delta vector {right arrow over (β)}. The attitude estimation filter state X, transition matrix Φ, attitude process noise matrix Q and measurement matrix H for the accelerometer can be represented in continuous time format as follows:

$\begin{matrix} {{X = \begin{pmatrix} \overset{\rightharpoonup}{\theta} \\ \overset{\rightharpoonup}{\beta} \end{pmatrix}},} & (18) \\ {{\Phi = \begin{pmatrix} {- {\overset{\rightharpoonup}{\omega}}_{x}} & {- I_{3 \times 3}} \\ O_{3 \times 3} & {{- \lambda^{- 1}} \cdot I_{3 \times 3}} \end{pmatrix}},} & (19) \\ {{Q = \begin{pmatrix} {{diag}\left( N_{\theta} \right)} & O_{3 \times 3} \\ O_{3 \times 3} & {{diag}\left( N_{\beta} \right)} \end{pmatrix}},} & (20) \\ {{H_{acc} = \begin{pmatrix} {\overset{\hat{\rightharpoonup}}{g}}_{x} & O_{3 \times 3} \end{pmatrix}},} & (21) \\ {H_{bias} = \begin{pmatrix} O_{3 \times 3} & I_{3 \times 3} \end{pmatrix}} & (22) \end{matrix}$

where λ is a Gauss-Markov time constant, O_(n×m) is an n×m zero matrix, I_(n×m) is an n×m identity matrix, and |{right arrow over (ω)}|_(x),|{right arrow over (ĝ)}|_(x) are left cross product matrices.

In practice, a second order discrete approximation can be used for the attitude estimation filter and temperature estimation filter. In the above formulations, an assumption is made that the process noise matrix Q for the attitude error and bias are independent and so can be specified by the matrix diagonals N_(θ) and N_(β). The measurement matrix can be the accelerometer measurement matrix, which can be defined in terms of the filter's current estimate of gravity {right arrow over (ĝ)} generated from the reference quaternion {right arrow over (q)}_(ref). Measurement noise matrices R for the temperature estimation filter and attitude estimation filter are assumed diagonal and have quantities that can be determined empirically using simulations or other known statistical methods. Initial values for the error covariance matrices P can also be selected empirically using simulations or other known statistical methods.

The matrices described above can be used in an extended Kalman filter formulation, which includes a time update phase and a measurement update phase as follows:

-   -   A. Time Update         -   1. Propagate state

{right arrow over ({circumflex over (x)} ⁻ _(k) =Φ{right arrow over ({circumflex over (x)} _(k-1) +Bū _(k-1)

-   -   -   2. Propagate error covariance

P _(k) ⁻ =ΦP _(k-1)Φ^(T) +Q

-   -   B. Measurement Update         -   1. Compute Kalman gain

K _(k) =P _(k) ⁻ H ^(T)(HP _(k) ⁻ H ^(T) +R)⁻¹

-   -   -   2. Update estimate with measurement and Kalman gain

{right arrow over ({circumflex over (x)} _(k) ={right arrow over ({circumflex over (x)} _(k) ⁻ +K _(k)({right arrow over (z)} _(k) −H{right arrow over ({circumflex over (x)} _(k) ⁻)

-   -   -   3. Update error covariance with Kalman gain

P _(k)=(I−K _(k) H)P _(k) ⁻

Low Pass Bias Estimates

There can be a number of components that eventually contribute to a gyro bias estimate. In general, these components can be divided into two categories: bias/temperature model and bias delta from the temperature model.

Generally, a temperature/bias relationship is maintained in system 100, which defines the mean bias value for a given temperature over time. This is a long-term relationship. Shorter-term variation from the mean bias at a given temperature—the bias delta vector ({right arrow over (β)})—can be assumed to be a Gauss-Markov noise model.

The bias delta vector can be updated through the Kalman filter formulation. These updates can come in one of three ways: through an accelerometer measurement update, direct measurement update coming from motion detector 104 or direct measurement update coming from the LPF.

In some implementations, a long-term running average of the temperature compensated angular rate vector {right arrow over (ω)}_(c) can be an early estimate of the bias delta vector {right arrow over (β)}. The LPF can be implemented as a first order auto-regressive filter LPF_(n)=α_(n)·LPF_(n-1)+(1−α_(n))·ω_(n) with a dynamic update rate. The compensated angular rate vector {right arrow over (ω)}_(c) values are fed into the LPF if the values are less than a predetermined threshold on the magnitude of the compensated angular rate vector. The update rate α_(n) can be chosen to be larger if the magnitude of {right arrow over (ω)}_(c) is larger, and smaller if the magnitude of {right arrow over (ω)}_(c) is smaller.

This estimate can be periodically applied (e.g., 5 Hz) as a direct measurement to the attitude estimation filter. The measurement noise can be modified to depend roughly on how long the LPF has been running. The purpose of the LPF is to allow for the update of {right arrow over (β)} in regions where significant uncertainty exists as defined through the attitude estimation filter's covariance matrix. These updates can be performed even when the device is moving slowly.

Exemplary Interference Mitigation Module

The optional interference mitigation module 114 can use the reference quaternion output by state estimator 108 to detect changes in the external magnetic field vector. The module keeps track of the last known magnetometer measurement vector {right arrow over (m)}_(k) at time k and the device's estimated attitude A_(k) at time k, which can be provided by state estimator 108 (e.g., provided by {right arrow over (q)}_(ref)). Module 114 transforms the magnetometer measurement vector {right arrow over (m)}_(k) into an estimated magnetic field vector in a reference global coordinate system using the inverse of A_(k):

{right arrow over (m)} _(k) ^(w) =A _(k) ⁻¹{right arrow over (m)}_(k).  (23)

The reference global coordinate system can include a same reference frame as the reference frame of the device's estimated attitude A_(k). The estimated magnetic field vector transformed at time k can be stored on a storage device as a reference for determining whether a subsequent magnetometer measurement vector is subject to interference.

At each offset-corrected magnetometer measurement vector {right arrow over (m)}_(i) at time i, module 114 reads the current estimated attitude A_(i) at time i and constructs a synthetic magnetometer measurement vector {right arrow over (m)}_(i) ^(s) at time i:

{right arrow over (m)} _(i) ^(s) =A _(i) ⁻¹ {right arrow over (m)} _(k) ^(w).

Exemplary pseudo code for calculating a synthetic magnetometer measurement vector gyroCompassMagnetic (e.g., {right arrow over (m)}_(i) ^(s)) using an attitude represented by RotationMatrix (e.g., A_(i)) and an estimated magnetic field vector represented by MagneticGlobalFrame (e.g., {right arrow over (m)}_(i) ^(w)) is listed below.

gyroCompassMagnetic=(RotationMatrix·mult(MagneticGlobalFrame));

If the magnetometer measurement vector {right arrow over (m)}_(k) expressed in the reference global coordinate system is substantially constant, the angle between vectors {right arrow over (m)}_(i) ^(s) and

${\overset{\rightharpoonup}{m}}_{i},\frac{\theta_{i} = {\cos^{- 1}\left( {m_{i}^{s} \cdot m_{i}} \right)}}{{{\overset{\rightharpoonup}{m}}_{i}^{s}}{{\overset{\rightharpoonup}{m}}_{i}}}$

should be zero. When the variance of θ_(i) within a defined window is below a threshold, and there are no other known sources of magnetometer interference present (e.g., a vibration source), the offset-corrected magnetometer measurement vector {right arrow over (m)}_(i) can be used to calculate compass heading. Otherwise, the synthetic magnetometer measurement vector m_(i) ^(s) can be used to calculate compass heading. The window can include a time period that encompasses one or more magnetometer measurements. Exemplary pseudo code for calculating the variance of θ_(i) is listed below.

// deltaAngle is an interior angle between magnetic (e.g., m _(i)) and // gyroCompassMagnetic (e.g., m _(i) ^(s)). float deltaAngle = (magnetic.interiorAngle(gyroCompassMagnetic)); // AngleVariance is a running buffer that sums the data AngleVariance.addSample(deltaAngle*deltaAngle); // varAngle is the square of the variance float varAngle = (AngleVariance.getSum( )/ AngleVariance.getCurrentSize( ));

In some implementations, a variance of magnitudes of magnetometer measurement vectors can be used in addition or as an alternative to the variance of the angle of θ_(i). When the variance in magnitudes satisfies a threshold, the offset-corrected magnetometer measurement vector {right arrow over (m)}_(t) can be used to calculate compass heading. Otherwise, the synthetic magnetometer measurement vector m_(i) ^(s) can be used to calculate compass heading. Exemplary pseudo code for calculating a magnitude of a vector is listed below.

//calculating a magnitude of a vector having three components x, y, and z. mag( ) const {   return sqrt( x*x + y*y + z*z); }

In some implementations, a variance of inclinations of magnetometer measurement vectors can be used in addition or as an alternative to the variance of θ_(i) and/or the variance of magnitudes. When the variance of inclinations satisfies a threshold, the offset-corrected magnetometer measurement vector {right arrow over (m)}_(i) can be used to calculate compass heading. Otherwise, the synthetic magnetometer measurement vector m_(i) ^(s) can be used to calculate compass heading. Exemplary pseudo code for calculating an inclination of a magnetometer measurement vector magnetic is listed below.

//inclination between magnetic vector magnetic (e.g., m _(i)) and gravity // vector gravity (e.g., g). inclination = 90.0f − (magnetic.interiorAngle(gravity));

The variance of θ_(i), variance of magnitudes, and variance of inclinations, individually or in combination, can be used as controls of a mode selector for selecting between a magnetometer mode and a coasting mode. In the magnetometer mode, the offset-corrected magnetometer measurement vector {right arrow over (m)}_(i) can be used for calculating the compass heading. In the coasting mode, the synthetic magnetometer measurement vector {right arrow over (m)}_(i) ^(s) can be used for calculating the compass heading.

The mode selector can be triggered by observation of data. The mode selector can be configured using various threshold values for the variance of θ_(i), the variance in magnitude, and the variance in inclination. When one or more of first threshold values are satisfied, the compass heading can be calculated using the synthetic magnetometer measurement vector {right arrow over (m)}_(i) ^(s); when one or more of second threshold values are satisfied, the compass heading can be calculated using the offset-corrected magnetometer measurement vector {right arrow over (m)}_(i). Exemplary pseudo code for switching from magnetometer mode to coasting mode is listed below.

// varMagnitude can measure a variance in magnitude. varInclination can // measure a variance in inclination. MaxAngleVariance, // MaxMagnitudeVariance, and MaxInclinationVariance are respective thresholds. if (varAngle > MaxAngleVariance || varMagnitude >   MaxMagnitudeVariance || varInclination >   MaxlnclinationVariance)) {   ActivateCoastingMode( ); }

The estimated magnetic field vector in the reference global coordinate system, as stored on a storage device, can be updated periodically or upon request. In some implementations, the estimated magnetic field vector in the reference global coordinate system can be updated when compass calibration improves, or when at least one of the variance of θ_(i), the variance of magnitude, and the variance in inclination falls below a threshold. Exemplary pseudo code for storing the estimated magnetic field vector in the reference global coordinate system is listed below.

if (NOT coasting && compass calibrated) {   if (compass calibration improved ||     (magnetic.interiorAngle(gyroCompassMagnetic)<=       MaxAngleUpdateThreshold) &&     magnetic.mag( ) − gyroCompassMagnetic.mag( ) >     Threshold ) {     MagneticGlobalFrame =     TransposeRotationMatrix.mult(magnetic);   } }

Exemplary Sensor Calibration Process Flow

FIG. 3 is a flow diagram of an exemplary process 300 for estimating model parameters and determining an estimated attitude based on the estimated model parameters. Process 300 can be implemented by a sensor data calibration system of a device, such as sensor measurement calibration system 100.

In some implementations, process 300 can begin by determining if a device is stationary (302). For example, a motion detector (e.g., motion detector 104) can use angular rates from the angular rate sensor (e.g., MEMS gyro) to determine if the device is stationary. In some implementations, a variance of window averaged angular rates can be compared against a threshold value to determine if the device is stationary, as described in reference to FIG. 1. In other implementations, other sensor data can be used to detect when the device is stationary, such as accelerations from accelerometer 112.

If the device is determined to be stationary (304), a calibration opportunity exists and a window averaged bias vector for the current temperature can be calculated based on the angular rate data output by the angular rate sensor (306). The window averaged bias vector and a corresponding temperature can be stored in a calibration database (308). Model parameters can be calculated from a linear fit of the bias vectors and temperatures stored in the calibration database (310). The estimated attitude of the device can be determined using the model parameters (312). The estimating can be implemented in two independent estimation filters: one filter for estimating temperature and one filter for estimating attitude. The estimation filters can be implemented using Kalman filter formulations. The estimated attitude can optionally be used to mitigate interference in other sensor measurements (314), such as a magnetometer measurement.

The Earth's Magnetic Field—Overview

FIG. 4A illustrates an exemplary Cartesian coordinate system for describing the Earth's geomagnetic field in accordance with some implementations. The Earth's geomagnetic field vector, {right arrow over (F)}, can be described by the orthogonal components X (northerly intensity), Y (easterly intensity) and Z (vertical intensity, positive downwards); total intensity F; horizontal intensity H; inclination (or dip) I and declination (or magnetic variation) D. Declination, inclination and total intensity can be computed from the orthogonal components using the equations

$\begin{matrix} {{D = {\arctan \left( \frac{Y}{X} \right)}},} & (24) \\ {{I = {\arctan \left( \frac{Z}{H} \right)}},} & (25) \\ {{F = \sqrt{H^{2} + Z^{2}}},{and}} & (26) \end{matrix}$

where H is given by

H=√{square root over (X ² +Y ²)}.  (27)

An angle Φ can be defined as the angle between the geomagnetic field vector, {right arrow over (F)}, and the Earth's gravitational acceleration vector

(which is aligned with the Z component of the Earth's geomagnetic field vector). The angle Φ can be determined from the inclination angle I, or Φ=90°−I. At any given position on Earth, the total intensity F is constant, regardless of magnetometer orientation. In addition, at any given position on Earth, the angle Φ is constant, regardless of magnetometer orientation. The International System of Units (SI) unit of magnetic field intensity most commonly used is the Tesla.

FIG. 4B illustrates an exemplary 2-axis magnetometer in accordance with some implementations. Magnetometers can be 2-axis or 3-axis and the processes described here apply to both types of sensors. In the interest of brevity, only a 2-axis magnetometer is described.

In some implementations, 2-axis magnetometer sensor configuration 100 can be used to calculate a heading for a variety of applications, including applications running on a mobile device. Sensor configuration 100 can include two magnetic field sensors 402, 404 mounted orthogonally on a board, substrate, or other mounting surface. Magnetic sensors 402, 404 can be included in an integrated circuit (IC) package with or without other sensors, such as accelerometers and gyros.

Sensor configuration 400 can be deployed in a host system environment that contains interfering magnetic fields. Since the Earth's magnetic field is a weak field (˜0.5 Gauss), nearby magnetic objects (co-located with the mobile device) can interfere with the accurate measurements of sensors 402, 404. A calibration procedure can be deployed to isolate and remove the local magnetic interference. One technique is to determine offsets or offset vector that can be subtracted from sensor measurements to get accurate measurements of the Earth's magnetic field. For 3-axis sensors, a third component, Z, can be adjusted with an offset as well.

In one exemplary calibration procedure for a 2-axis magnetometer, each heading computation can be assumed to be made with a number of valid X and Y sensor readings, which can be taken with a minimal delay between each reading. For this sensor configuration, sensors 402, 404 are at right angles with respect to each other and lie level with respect to the Earth's surface. By convention, the positive end of the X-axis points to the North and the positive end of the Y-axis points to the East. For this example, two consecutive sensor readings are made during calibrations that are 180 degrees apart. These measurements can be represented by (X1, Y1) and (X2, Y2). The Earth's magnetic field in any given direction as measured with no interfering field can be represented by offset pair (X_(E), Y_(E)). Magnetic interference can be represented by (X_(offset), Y_(offset)). Using these mathematical conventions, the two sensor readings can be represented by

X1=X _(E) Xoffset;  (28)

Y1=Y _(E) +Yoffset;

X2=−X _(E) +X _(offset); and

Y2=−Y _(E) +Yoffset.

Assuming the magnetometer is fixed with respect to the host system (e.g., a magnetometer installed in a mobile phone), the readings (X1, Y1) and (X2, Y2) taken during calibration will both contain the same interference values (X_(offset), Y_(offset)). Since the magnetometer readings taken during calibration are 180 degrees apart the readings are equal but opposite in sign. Solving the equations above for X_(offset) and Y_(offset) yields

Xoffset=(X1+X2)/2, and  (29)

Yoffset=(Y1+Y2)/2.

A measurement of the sensor readings can be represented by (X_(E), Y_(E)). In some implementations, a basic calculation of the heading can be performed using X_(E) and Y_(E) and the equation:

A _(heading)=arctan(Y _(E) ,X _(E)),  (30)

where the resulting heading A_(heading) can be mapped into the correct quadrant based on the signs of X_(E) and Y_(E). The heading A_(heading), calculated from measurements provided by the magnetometer, is a magnetic heading that can be corrected by combining the declination with the heading A_(heading) to identify a heading relative to true north.

Other implementations are possible. For example, the heading can also be calibrated based on the orientation of the device obtained from an accelerometer, inclination, GPS, and other types of corrections or calibrations.

Once the offsets are determined, the offsets can be subtracted from a subsequent sensor reading (X3, Y3).

X _(E) =X ₃ −X _(offset),  (31)

Y _(E) =Y3−Y _(offset).

If a magnetometer is included in a mobile device, such as a mobile phone, the local magnetic interference can change. For example, if the user docks his mobile device (containing the magnetometer) in his car, magnetic objects in the car could change the local interference. This could result in the calibration offsets becoming invalid. If the offsets are invalid, then the magnetometer can perform a recalibration procedure to generate new offsets. This recalibration procedure can be a tedious process for the user if performed often, and may require the user to manipulate the mobile device through a number of angles.

FIG. 4C is a block diagram of an exemplary system 410 for determining heading using magnetometer data and angular rate data. System 410 can be a subsystem of a mobile device. System 410 can include mode selector 412. Mode selector 412 can be configured to switch between a magnetometer mode and a coasting mode. The switching can be based on the quality of the magnetometer measurement that is fed into mode selector 412, or one or more notifications of magnetic interference.

A first set of inputs fed into mode selector 412 can include offset-corrected magnetometer measurement as described above in reference to FIG. 1.

A second set of inputs fed into mode selector 412 can include the synthesized magnetometer measurement generated by synthesizer 414. Synthesizer 414 can generate the synthesized magnetometer measurement using an estimated magnetic field vector in a reference global coordinate system and an attitude of the mobile device.

Mode selector 412 can perform the switching between the magnetometer mode and the coasting mode based on the quality of the offset-corrected magnetometer measurement. For example, a difference (measured by an interior angle) between the offset-corrected magnetometer measurement and the synthesized magnetometer measurement can be measured. A variance of the difference can be calculated. If the variance reaches or exceeds a threshold, mode selector 412 can switch to the coasting mode. If the variance is below the threshold, mode selector 412 can switch to the magnetometer mode.

In some implementations, mode selector 412 can perform the switching based the magnetometer measurement. If the magnetometer measurement includes a variance in magnitude and/or inclination reaches or exceeds a threshold, mode selector 412 can switch to the coasting mode. Otherwise, mode selector 412 can switch to the magnetometer mode.

In some implementations, mode selector 412 can perform the switching between the magnetometer mode and the coasting mode based on a notification. The notification can include an indication that a magnetic interference has occurred or is about to occur. In response to the notification, mode selector 412 can switch from the magnetometer mode to the coasting mode. For example, if a speaker of the mobile device is about to be activated, a notification can be sent to mode selector 412. Upon receiving the notification, mode selector 412 can enter coasting mode to avoid magnetic interference from the speaker.

One of the offset-corrected magnetometer measurement and the synthesized magnetometer measurement selected by mode selector 412 can be fed to heading calculator 416. Heading calculator 416 can calculate a heading of the mobile device, and provide the heading to an application program (e.g., a compass program or a map program). The heading can be output to an audio or visual output device.

FIG. 4D is a flow diagram of an exemplary process 430 of determining heading using magnetometer data and angular rate data. For convenience, process 430 will be described in reference to system (e.g., system 410) that implements process 430.

The system can determine (432) a heading of a mobile device using magnetometer data. Determining the heading using the magnetometer data can include determining the heading using offset-corrected magnetometer data as described above with respect to FIG. 1.

The system can receive (434) an indication that the magnetometer data may be inaccurate. The indication can include a determination of a quality of the magnetometer data or a notification.

To determine the quality of the magnetometer data, the system can store an estimated magnetic field vector in a reference global coordinate system on a storage device. The system can generate the estimated magnetic field vector in the reference global coordinate system using historical magnetometer data that are determined to be accurate (e.g., magnetometer measurement vector {right arrow over (m)}_(k) at time k) and historical angular rate data that temporally correspond to the accurate historical magnetometer data (e.g., an inverse of the mobile device's estimated attitude A_(k) at time k).

Using current angular rate data (e.g., the mobile device's current estimated attitude A_(i) at current time i) and the estimated magnetic field vector in the reference global coordinate system, the mobile device can generate synthetic magnetometer data. The synthetic magnetometer data can include synthetic magnetometer measurement vector {right arrow over (m)}_(i) ^(s) at time i. The system can determine a heading of the mobile device using the synthetic magnetometer data.

In some implementations, receiving the indication that the magnetometer data may be inaccurate can include determining multiple magnitudes of magnetic vectors in a sample the magnetometer data and determining that a variance of the magnitudes satisfies a threshold value. The magnetic vectors can include magnetic vectors measured in a sample window (e.g., the last n measured magnetic vectors).

In some implementations, receiving the indication that the magnetometer data may be inaccurate can include determining multiple inclinations of magnetic vectors in a sample of the magnetometer data and determining that a variance of the inclinations satisfies a threshold value. Each of the inclinations can be determined based on an angle between a magnetic vector and a local gravitational acceleration vector.

Receiving (434) an indication that the magnetometer data may be inaccurate can include receiving a notification that a magnetic interference has occurred or will occur. The magnetic interference can be generated from a component of the mobile device that draws at least a threshold amount of electric current. In some implementations, the magnetic interference can be generated from a speaker, camera, or a vibrator of the mobile device.

In response to the received indication that the magnetometer data may be inaccurate, the system can determine (436) the heading of the mobile device using angular rate data. Determining the heading of the mobile device using angular rate data can include determining a heading of the mobile device using the synthetic magnetometer data.

The system can determine (438) that the magnetometer data are accurate within an accuracy range. Determining that the magnetometer data are accurate within the accuracy range can include determining that a variance of an angle (e.g., θ_(i)) between a vector of the synthetic magnetometer data (e.g., synthetic magnetometer measurement vector {right arrow over (m)}_(i) ^(s)) and a vector of the magnetometer data (e.g., magnetometer measurement vector {right arrow over (m)}_(i)) satisfies a threshold value. Upon determining that the magnetometer data are accurate within the accuracy range, the system can resume determining (432) the heading of the mobile device using magnetometer data. If the magnetometer data are not accurate within the accuracy range, the system can continue determining (436) the heading using the angular rate data.

Exemplary Device Architecture

FIG. 5 is a block diagram of an exemplary device hardware architecture for implementing the sensor calibration system 100 and processes referenced in FIGS. 1-3. The device can include memory interface 502, one or more data processors, image processors and/or processors 504, and peripherals interface 506. Memory interface 502, one or more processors 504, and/or peripherals interface 506 can be separate components or can be integrated in one or more integrated circuits. The various components in the device, for example, can be coupled by one or more communication buses or signal lines.

Sensors, devices, and subsystems can be coupled to peripherals interface 506 to facilitate multiple functionalities. For example, angular rate sensor 510 (e.g., a MEMS gyro), magnetometer sensor 512. Location processor 514 (e.g., GPS receiver) can be connected to peripherals interface 506 to provide geopositioning. Accelerometer 516 can also be connected to peripherals interface 506 to provide data that can be used to determine change of speed and direction of movement of the mobile device.

Camera subsystem 520 and an optical sensor 522, e.g., a charged coupled device (CCD) or a complementary metal-oxide semiconductor (CMOS) optical sensor, can be utilized to facilitate camera functions, such as recording photographs and video clips.

Communication functions can be facilitated through one or more wireless communication subsystems 524, which can include radio frequency receivers and transmitters and/or optical (e.g., infrared) receivers and transmitters. The specific design and implementation of the communication subsystem 524 can depend on the communication network(s) over which a mobile device is intended to operate. For example, a mobile device can include communication subsystems 524 designed to operate over a GSM network, a GPRS network, an EDGE network, a Wi-Fi or WiMax network, and a Bluetooth network. In particular, the wireless communication subsystems 524 can include hosting protocols such that the mobile device can be configured as a base station for other wireless devices.

Audio subsystem 526 can be coupled to a speaker 528 and a microphone 530 to facilitate voice-enabled functions, such as voice recognition, voice replication, digital recording, and telephony functions.

I/O subsystem 540 can include touch screen controller 542 and/or other input controller(s) 544. Touch-screen controller 542 can be coupled to a touch screen 546 or pad. Touch screen 546 and touch screen controller 542 can, for example, detect contact and movement or break thereof using any of a plurality of touch sensitivity technologies, including but not limited to capacitive, resistive, infrared, and surface acoustic wave technologies, as well as other proximity sensor arrays or other elements for determining one or more points of contact with touch screen 546.

Other input controller(s) 544 can be coupled to other input/control devices 548, such as one or more buttons, rocker switches, thumb-wheel, infrared port, USB port, and/or a pointer device such as a stylus. The one or more buttons (not shown) can include an up/down button for volume control of speaker 528 and/or microphone 530.

In one implementation, a pressing of the button for a first duration may disengage a lock of the touch screen or pad 546; and a pressing of the button for a second duration that is longer than the first duration may turn power to the device on or off. The user may be able to customize a functionality of one or more of the buttons. The touch screen 546 can, for example, also be used to implement virtual or soft buttons and/or a keyboard.

In some implementations, the device can present recorded audio and/or video files, such as MP3, AAC, and MPEG files. In some implementations, the device can include the functionality of an MP3 player.

Memory interface 502 can be coupled to memory 550. Memory 550 can include high-speed random access memory and/or non-volatile memory, such as one or more magnetic disk storage devices, one or more optical storage devices, and/or flash memory (e.g., NAND, NOR). Memory 550 can store operating system 552, such as Darwin, RTXC, LINUX, UNIX, OS X, WINDOWS, or an embedded operating system such as VxWorks. Operating system 552 may include instructions for handling basic system services and for performing hardware dependent tasks. In some implementations, operating system 552 can include a kernel (e.g., UNIX kernel).

Memory 550 may also store communication instructions 554 to facilitate communicating with one or more additional devices, one or more computers and/or one or more servers. Memory 550 may include graphical user interface instructions 556 to facilitate graphic user interface processing; sensor processing instructions 558 to facilitate sensor-related processing and functions; phone instructions 560 to facilitate phone-related processes and functions; electronic messaging instructions 562 to facilitate electronic-messaging related processes and functions; web browsing instructions 564 to facilitate web browsing-related processes and functions; media processing instructions 566 to facilitate media processing-related processes and functions; GPS/Navigation instructions 568 to facilitate GPS and navigation-related processes and instructions; and camera instructions 570 to facilitate camera-related processes and functions. The memory 550 may also store other software instructions (not shown), such as security instructions, web video instructions to facilitate web video-related processes and functions, and/or web shopping instructions to facilitate web shopping-related processes and functions. In some implementations, the media processing instructions 566 are divided into audio processing instructions and video processing instructions to facilitate audio processing-related processes and functions and video processing-related processes and functions, respectively. An activation record and International Mobile Equipment Identity (IMEI) or similar hardware identifier can also be stored in memory 550. Memory 550 can include magnetometer data 572 and one or more estimated magnetic field vectors 574.

Each of the above identified instructions and applications can correspond to a set of instructions for performing one or more functions described above. These instructions need not be implemented as separate software programs, procedures, or modules. Memory 550 can include additional instructions or fewer instructions. Furthermore, various functions of the mobile device may be implemented in hardware and/or in software, including in one or more signal processing and/or application specific integrated circuits.

The features described can be implemented in digital electronic circuitry, in computer hardware, firmware, software, or in combinations of them. The features can be implemented in a computer program product tangibly embodied in an information carrier, e.g., in a machine-readable storage device, for execution by a programmable processor; and method steps can be performed by a programmable processor executing a program of instructions to perform functions of the described implementations by operating on input data and generating output. Alternatively or addition, the program instructions can be encoded on a propagated signal that is an artificially generated signal, e.g., a machine-generated electrical, optical, or electromagnetic signal, that is generated to encode information for transmission to suitable receiver apparatus for execution by a programmable processor.

The described features can be implemented advantageously in one or more computer programs that are executable on a programmable system including at least one programmable processor coupled to receive data and instructions from, and to transmit data and instructions to, a data storage system, at least one input device, and at least one output device. A computer program is a set of instructions that can be used, directly or indirectly, in a computer to perform a certain activity or bring about a certain result. A computer program can be written in any form of programming language (e.g., Objective-C, Java), including compiled or interpreted languages, and it can be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.

Suitable processors for the execution of a program of instructions include, by way of example, both general and special purpose microprocessors, and the sole processor or one of multiple processors or cores, of any kind of computer. Generally, a processor will receive instructions and data from a read-only memory or a random access memory or both. The essential elements of a computer are a processor for executing instructions and one or more memories for storing instructions and data. Generally, a computer will also include, or be operatively coupled to communicate with, one or more mass storage devices for storing data files; such devices include magnetic disks, such as internal hard disks and removable disks; magneto-optical disks; and optical disks. Storage devices suitable for tangibly embodying computer program instructions and data include all forms of non-volatile memory, including by way of example semiconductor memory devices, such as EPROM, EEPROM, and flash memory devices; magnetic disks such as internal hard disks and removable disks; magneto-optical disks; and CD-ROM and DVD-ROM disks. The processor and the memory can be supplemented by, or incorporated in, ASICs (application-specific integrated circuits).

To provide for interaction with a user, the features can be implemented on a computer having a display device such as a CRT (cathode ray tube) or LCD (liquid crystal display) monitor for displaying information to the user and a keyboard and a pointing device such as a mouse or a trackball by which the user can provide input to the computer.

The features can be implemented in a computer system that includes a back-end component, such as a data server, or that includes a middleware component, such as an application server or an Internet server, or that includes a front-end component, such as a client computer having a graphical user interface or an Internet browser, or any combination of them. The components of the system can be connected by any form or medium of digital data communication such as a communication network. Examples of communication networks include, e.g., a LAN, a WAN, and the computers and networks forming the Internet.

The computer system can include clients and servers. A client and server are generally remote from each other and typically interact through a network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.

One or more features or steps of the disclosed embodiments can be implemented using an API. An API can define on or more parameters that are passed between a calling application and other software code (e.g., an operating system, library routine, function) that provides a service, that provides data, or that performs an operation or a computation.

The API can be implemented as one or more calls in program code that send or receive one or more parameters through a parameter list or other structure based on a call convention defined in an API specification document. A parameter can be a constant, a key, a data structure, an object, an object class, a variable, a data type, a pointer, an array, a list, or another call. API calls and parameters can be implemented in any programming language. The programming language can define the vocabulary and calling convention that a programmer will employ to access functions supporting the API.

In some implementations, an API call can report to an application the capabilities of a device running the application, such as input capability, output capability, processing capability, power capability, communications capability, etc.

A number of implementations have been described. Nevertheless, it will be understood that various modifications may be made. For example, elements of one or more implementations may be combined, deleted, modified, or supplemented to form further implementations. As yet another example, the logic flows depicted in the figures do not require the particular order shown, or sequential order, to achieve desirable results. In addition, other steps may be provided, or steps may be eliminated, from the described flows, and other components may be added to, or removed from, the described systems. Accordingly, other implementations are within the scope of the following claims. 

1. A computer-implemented method performed by one or more processors of a mobile device, comprising: determining a heading of the mobile device using magnetometer data; receiving an indication that the magnetometer data may be inaccurate; in response to the received indication, determining the heading of the mobile device using angular rate data; determining that the magnetometer data are accurate within an accuracy range; and upon determining that the magnetometer data are accurate within the accuracy range, resuming determining the heading of the mobile device using the magnetometer data.
 2. The method of claim 1, further comprising storing an estimated magnetic field vector in a reference global coordinate system, the estimated magnetic field vector in the reference global coordinate system generated using historical magnetometer data that are determined to be accurate and historical angular rate data that temporally correspond to the accurate historical magnetometer data.
 3. The method of claim 2, further comprising generating synthetic magnetometer data using the estimated magnetic field vector in the reference global coordinate system and current angular rate data.
 4. The method of claim 3, where determining that the magnetometer data are accurate within the accuracy range includes determining that a variance of an angle between a vector of the synthetic magnetometer data and a vector of the magnetometer data satisfies a threshold value.
 5. The method of claim 3, where determining the heading of the mobile device using the angular rate data includes determining the heading of the mobile device using the synthetic magnetometer data.
 6. The method of claim 1, where receiving the indication that the magnetometer data may be inaccurate includes receiving a notification that a magnetic interference will occur.
 7. The method of claim 6, where the magnetic interference is generated from a component of the mobile device that draws at least a threshold amount of electric current.
 8. The method of claim 6, where the magnetic interference is generated from a component of the mobile device, the component including at least one of a speaker, a camera, and a vibrator.
 9. The method of claim 1, where receiving the indication that the magnetometer data may be inaccurate includes: determining a plurality of magnitudes of magnetic vectors in a sample of the magnetometer data; and determining that a variance of the magnitudes satisfies a threshold value.
 10. The method of claim 1, where receiving the indication that the magnetometer data may be inaccurate includes: determining a plurality of inclinations of magnetic vectors in a sample of the magnetometer data; and determining that a variance of the inclinations satisfies a threshold value.
 11. The method of claim 10, where each of the inclinations is determined based on an angle between a magnetic vector and a gravitational acceleration vector.
 12. A computer program product tangibly stored on a mobile device, operable to cause the mobile device to perform operations comprising: determining a heading of the mobile device using magnetometer data; receiving an indication that the magnetometer data may be inaccurate; in response to the received indication, determining the heading of the mobile device using angular rate data; determining that the magnetometer data are accurate within an accuracy range; and upon determining that the magnetometer data are accurate within the accuracy range, resuming determining the heading of the mobile device using the magnetometer data.
 13. The product of claim 12, the operations further comprising storing an estimated magnetic field vector in a reference global coordinate system, the estimated magnetic field vector in the reference global coordinate system generated using historical magnetometer data that are determined to be accurate and historical angular rate data that temporally correspond to the accurate historical magnetometer data.
 14. The product of claim 13, the operations further comprising generating synthetic magnetometer data using the estimated magnetic field vector in the reference global coordinate system and current angular rate data.
 15. The product of claim 14, where determining that the magnetometer data are accurate within the accuracy range includes determining that a variance of an angle between a vector of the synthetic magnetometer data and a vector of the magnetometer data satisfies a threshold value.
 16. The product of claim 14, where determining the heading of the mobile device using the angular rate data includes determining the heading of the mobile device using the synthetic magnetometer data.
 17. The product of claim 12, where receiving the indication that the magnetometer data may be inaccurate includes receiving a notification that a magnetic interference will occur.
 18. A system comprising: a mobile device configured to perform operations comprising: determining a heading of the mobile device using magnetometer data; receiving an indication that the magnetometer data may be inaccurate; in response to the received indication, determining the heading of the mobile device using angular rate data; determining that the magnetometer data are accurate within an accuracy range; and upon determining that the magnetometer data are accurate within the accuracy range, resuming determining the heading of the mobile device using the magnetometer data.
 19. The system of claim 18, the operations further comprising storing an estimated magnetic field vector in a reference global coordinate system, the estimated magnetic field vector in the reference global coordinate system generated using historical magnetometer data that are determined to be accurate and historical angular rate data that temporally correspond to the accurate historical magnetometer data.
 20. The system of claim 19, the operations further comprising generating synthetic magnetometer data using the estimated magnetic field vector in the reference global coordinate system and current angular rate data. 